<?php

namespace MyBlog\Http\Controllers\backend;

use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Input;
use MyBlog\Models\Gallery;
use MyBlog\Models\Category;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use MyBlog\Models\GalleryImg;
use Illuminate\Database\Eloquent\Model;
use MyBlog\Libs\QiniuUtils;

class GalleryImgController extends BaseController
{
    public function index($gallery) {
        $imgs = GalleryImg::where('gallery_id', $gallery->id)
        		->orderBy('id', 'desc')->get();
        
        return view('backend/gallery_imgs', compact('imgs', 'gallery'));
    }
    
    public function create($gallery) {
    	$galleryImg = new GalleryImg();
    	return view('backend/gallery_img_form', compact('galleryImg', 'gallery'));
    }
    
    public function store($gallery) {
    	$input = Input::all();
    	$validation = Validator::make($input, GalleryImg::$rules, GalleryImg::$msgs);
    	if($validation->fails()) {
    		return Redirect::back()
	    		->withInput()
	    		->withErrors($validation);
    	}
    	$input['img_path'] = QiniuUtils::upload($input['img_path']);
    	GalleryImg::create($input);
    	return redirect('backend/galleries');
    }

    public function destory() {

    }
}
